package hardcode2013;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpUtil {
	
	public static void FinalRedirect(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String red = req.getParameter("redirect");
		if (red != null)
			resp.sendRedirect(red);
	}
	
	public static void ErrorRedirect(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String red = req.getParameter("redirect_error");
		if (red != null)
			resp.sendRedirect(red);
		else
			FinalRedirect(req, resp);
	}
	
	public static void HomeRedirect(HttpServletResponse resp) throws IOException {
		resp.sendRedirect("/");
	}
	
	public static void ExitWithMsg(String message, HttpServletRequest req, HttpServletResponse resp) throws IOException {
		SessionUtil.setMessage(req, message);
		ErrorRedirect(req, resp);
	}
}
